<script setup lang="ts">
// 1.由于需要点击搜索按钮携带参数跳转页面因此需要使用到链式编程
/*
具体步骤:
1.导入useRouter
2.实例化对象
*/
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const keyword = ref('')
const searchClick = () => {
  console.log('点击了搜索按钮')
  /*
  写法1:通过path路径跳转语法
  router.push('/search')
  通过path跳转且携带参数
  router.push({
    path: '/search',
    query: {
      keywords: '哈哈哈',
      name:'张三',
      age: 18
    },n
  })

*/
  // 写法2:通过name属性跳转语法
  // router.push({
  //   name: 'search',
  // })
  // 通过name属性跳转并传递参数
  router.push({
    name:'search',
    params:{
      key:keyword.value
    }
  })
}
</script>

<template>
  <div class="home">
    <div class="logo-box"></div>
    <div class="search-box">
      <input type="text" v-model="keyword" />
      <button @click="searchClick">搜索一下</button>
    </div>
    <div class="hot-link">
      热门搜索：
      <!-- 查询参数传参 -->
      <!-- <router-link to="/search?query='黑马程序员'">黑马程序员</router-link>
      <router-link to="/search?query='前端培训'">前端培训</router-link>
      <router-link to="/search?query='如何成为前端大牛'">如何成为前端大牛</router-link> -->
      <!-- 动态路由传参 -->
      <router-link to="/search/黑马程序员">黑马程序员</router-link>
      <router-link to="/search/前端培训">前端培训</router-link>
      <router-link to="/search/如何成为前端大牛">如何成为前端大牛</router-link>
    </div>
  </div>
</template>

<style scoped>
.logo-box {
  height: 150px;
  background: url('@/assets/logo.jpeg') no-repeat center;
}

.search-box {
  display: flex;
  justify-content: center;
}

.search-box input {
  width: 400px;
  height: 30px;
  line-height: 30px;
  border: 2px solid #c4c7ce;
  border-radius: 4px 0 0 4px;
  outline: none;
}

.search-box input:focus {
  border: 2px solid #ad2a26;
}

.search-box button {
  width: 100px;
  height: 36px;
  border: none;
  background-color: #ad2a26;
  color: #fff;
  position: relative;
  left: -2px;
  border-radius: 0 4px 4px 0;
}

.hot-link {
  width: 508px;
  height: 60px;
  line-height: 60px;
  margin: 0 auto;
}

.hot-link a {
  margin: 0 5px;
}
</style>
